package kr.hkit.powerjava.chapter17.submit;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JLabel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.JRadioButton;

import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.border.LineBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.UIManager;
import java.awt.GridLayout;

public class Swing3 extends JPanel implements ActionListener  {
	private JLabel lblNewLabel_2;
	private JLabel lblNewLabel_3;
	private JPanel panelRadio;
	private JRadioButton rdbtnSmall;
	private JRadioButton rdbtnMedium;
	private JRadioButton rdbtnLarge;
	private JPanel panelOrder;
	private JPanel panelResult;

	public Swing3() {
		initialize();
	}
	
	private void initialize() {
		setLayout(new BorderLayout(0, 0));
		
		panelOrder = new JPanel();
		add(panelOrder, BorderLayout.NORTH);
		
		lblNewLabel_2 = new JLabel("어떤 크기의 커피를 주문하시겠습니까?");
		panelOrder.add(lblNewLabel_2);
		lblNewLabel_2.setFont(new Font("맑은 고딕", Font.BOLD, 18));
		lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
		
		panelRadio = new JPanel();
		add(panelRadio, BorderLayout.CENTER);
		
		Border border= BorderFactory.createTitledBorder("SIZE"); //경계선
		panelRadio.setBorder(border);
		
		rdbtnSmall = new JRadioButton("Small Size");
		rdbtnSmall.setFont(new Font("맑은 고딕", Font.BOLD, 15));
		rdbtnSmall.setHorizontalAlignment(SwingConstants.CENTER);
		rdbtnSmall.addActionListener(this);
		rdbtnMedium = new JRadioButton("Medium Size");
		rdbtnMedium.setHorizontalAlignment(SwingConstants.CENTER);
		rdbtnMedium.setFont(new Font("맑은 고딕", Font.BOLD, 15));
		rdbtnMedium.addActionListener(this);
		rdbtnLarge = new JRadioButton("Large Size");
		rdbtnLarge.setHorizontalAlignment(SwingConstants.CENTER);
		rdbtnLarge.setFont(new Font("맑은 고딕", Font.BOLD, 15));
		rdbtnLarge.addActionListener(this);
		
		ButtonGroup size = new ButtonGroup(); //라디오버튼 그룹
		size.add(rdbtnSmall);
		size.add(rdbtnMedium);
		size.add(rdbtnLarge);
		panelRadio.setLayout(new GridLayout(0, 3, 0, 0));
		
		panelRadio.add(rdbtnSmall);
		panelRadio.add(rdbtnMedium);
		panelRadio.add(rdbtnLarge);
		
		panelResult = new JPanel();
		add(panelResult, BorderLayout.SOUTH);
		
		
		lblNewLabel_3 = new JLabel("크기가 선택되지 않았습니다.");
		panelResult.add(lblNewLabel_3);
		lblNewLabel_3.setFont(new Font("맑은 고딕", Font.BOLD, 15));
		lblNewLabel_3.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_3.setForeground(Color.RED);
	}
	

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == rdbtnMedium) {
			actionPerformedRdbtnMedium(e);
		}
		if (e.getSource() == rdbtnSmall) {
			actionPerformedRdbtnSmall(e);
		}
		if (e.getSource() == rdbtnLarge) {
			actionPerformedRdbtnLarge(e);
		}
	}
	protected void actionPerformedRdbtnSmall(ActionEvent e) {
		if (e.getSource() == rdbtnSmall) {
			lblNewLabel_3.setText("Small Size가 선택되었습니다.");
		}
	}
	protected void actionPerformedRdbtnMedium(ActionEvent e) {
		if (e.getSource() == rdbtnMedium) {
			lblNewLabel_3.setText("Medium Size가 선택되었습니다.");
		}
	}
	protected void actionPerformedRdbtnLarge(ActionEvent e) {
		if (e.getSource() == rdbtnLarge) {
			lblNewLabel_3.setText("Large Size가 선택되었습니다.");
		}
	}
}
